/*
 * @description Messages related to store process
 * @see src/edu/cmu/cs/stage3/alice/authoringtool/AuthoringTool.java: void dialogInit (): 'worldStoreProgressPane = new StoreElementProgressPane(...)'
 */

package edu.cmu.cs.stage3.alice.authoringtool.dialog;

import edu.cmu.cs.stage3.resourceBundle.I18n;

import edu.cmu.cs.stage3.alice.authoringtool.AuthoringTool;
import edu.cmu.cs.stage3.progress.ProgressCancelException;
import edu.cmu.cs.stage3.progress.ProgressPane;

public class StoreElementProgressPane extends ProgressPane {

 private edu.cmu.cs.stage3.alice.core.Element m_element;
 private java.io.File m_file;
 private java.util.Dictionary m_filnameToByteArrayMap;
 private boolean m_wasSuccessful = false;

 public StoreElementProgressPane (String title, String preDescription ) {
  super( title, preDescription );
  }

 public boolean wasSuccessful () {
  return m_wasSuccessful;
  }

 //Rem @Override
 // protected void construct() throws ProgressCancelException
 //L in order to be accedd by: AuthoringTool.loadWorld(final DirectoryTreeLoader loader,Object path,boolean askForSaveIfNecessary)'
 public void construct () throws ProgressCancelException { //L
  m_wasSuccessful = false;
  try {
   // System.out.println("StoreElementProgressPane.java: construct() -> store(...)");
   m_element.store( m_file, this, m_filnameToByteArrayMap );
   m_wasSuccessful = true;
  } catch( ProgressCancelException pce ) {
   throw pce;
  } catch( Throwable t ) {
   StringBuffer sb = new StringBuffer();
   sb.append( I18n.getString("bugErrorOccurred") ); //L "An error has occurred while attempting to save your world.\nThis is a critical situation that needs to be dealt with immediately.\n\n"
   if (t instanceof java.io.IOException) {
    sb.append( I18n.getString("bugLackSpace") ); //L "This may be the result of not having enough space on the target drive.\nIf possible,\n    attempt to save your world to a different drive"
                                                 //L ", or\n    free up some space and \"Save As\" to a different file.\n\nNOTE: If unsuccessful, please"
    }
   // else {
   //  sb.append( I18n.getString("bugNote") ); //L "NOTE: Please"
   //  }
   // sb.append( I18n.getString("bugCheck") ); //L " check for a directory co-located with \nyour world named \"Backups of <YourWorldNameHere>\" which \nshould contain previously saved versions of your world.\n"
   sb.append( I18n.getString("bugSorryNote") + "\n\n");
   //L "\nWe at the Alice Team apologize for any work you have lost and \nimplore you to PLEASE SUBMIT THIS BUG REPORT.\n"
   //L "Attaching your world along with recounting any steps you performed \nsince your last successful save would be incredibly valuable to us.\n"
   //L "\nPlease accept our sincerest apologies.  The Alice Team."
   AuthoringTool.getInstance().showSaveErrorDialog( sb.toString(), t );
   }
  }

 public void setElement (edu.cmu.cs.stage3.alice.core.Element element ) {
  m_element = element;
  }

 public void setFile (java.io.File file ) {
  m_file = file;
  }

 public void setFilnameToByteArrayMap (java.util.Dictionary filnameToByteArrayMap ) {
  m_filnameToByteArrayMap = filnameToByteArrayMap;
  }

 }
